Code
library(tidyverse)
library(leaflet)
library(geojsonio)
library(leaflet.extras)with leaflet
Tony Duan
Popups are small boxes containing arbitrary HTML, that point to a specific point on the map.
content <- paste(sep = "<br/>",
"<b><a href='https://www.samurainoodle.com/'>Samurai Noodle</a></b>",
"606 5th Ave. S",
"Seattle, WA 98138"
)
leaflet() %>% addTiles() %>%
setView(-122.327298, 47.597131,zoom = 12) %>%
addPopups(-122.327298, 47.597131, content,
#options = popupOptions(closeButton = FALSE)
options = popupOptions(closeButton = FALSE)
)A label is a textual or HTML content that can attached to markers and shapes to be always displayed or displayed on mouse over. Unlike popups you don’t need to click a marker/polygon for the label to be shown.
深圳市:
广东省 2021 人均gpd usd:
data source:广东统计年鉴2022
pal <- colorNumeric("viridis", NULL)
leaflet(map_sf002) %>%
addTiles() %>%
addPolygons(smoothFactor = 0.3, fillOpacity = 0.5,weight = 1,
fillColor = ~ pal(per_gpd_usd)
,popup = ~ paste0(
"城市:", name, "<br/>",
"<hr/>",
"人均gpd:", per_gpd_usd, "(美万)", "<br/>"
)
,label = lapply(paste0(
"城市:", "<b>", map_sf002$name, "</b>", "<br/>",
"人均gpd 美元:", map_sf002$per_gpd_usd, "<br/>",
"人均gpd 人民币:", map_sf002$per_gpd_rmb, "<br/>",
"人口:", round(map_sf002$total_gpd_rmb*10000000/map_sf002$per_gpd_rmb), "<br/>"
), htmltools::HTML)
)%>% addLegend(
position = "bottomright", title = "人均gpd(美元)",
pal = pal, values = ~per_gpd_usd, opacity = 1.0
)https://zh.wikipedia.org/wiki/%E5%B9%BF%E4%B8%9C%E5%90%84%E5%9C%B0%E7%BA%A7%E5%B8%82%E5%9C%B0%E5%8C%BA%E7%94%9F%E4%BA%A7%E6%80%BB%E5%80%BC%E5%88%97%E8%A1%A8
[1] 34
Simple feature collection with 1 feature and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 119.3183 ymin: 21.75147 xmax: 124.5656 ymax: 25.92592
Geodetic CRS: WGS 84
# A tibble: 1 × 5
adcode name center level geometry
<chr> <chr> <chr> <chr> <MULTIPOLYGON [°]>
1 710000 台湾省 121.509062,25.044332 province (((119.5543 23.68248, 119.555 23.…
[1] 334
Simple feature collection with 1 feature and 4 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 113.5215 ymin: 22.65421 xmax: 114.2603 ymax: 23.14205
Geodetic CRS: WGS 84
# A tibble: 1 × 5
adcode name center level geometry
<chr> <chr> <chr> <chr> <POLYGON [°]>
1 441900 东莞市 113.746262,23.046237 city ((114.2292 22.81251, 114.2278 22.813…
Simple feature collection with 1 feature and 4 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 113.157 ymin: 22.20104 xmax: 113.692 ymax: 22.7726
Geodetic CRS: WGS 84
# A tibble: 1 × 5
adcode name center level geometry
<chr> <chr> <chr> <chr> <POLYGON [°]>
1 442000 中山市 113.382391,22.521113 city ((113.5687 22.41193, 113.5666 22.412…
Simple feature collection with 1 feature and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 115.9267 ymin: 20.58265 xmax: 116.9338 ymax: 21.12693
Geodetic CRS: WGS 84
# A tibble: 1 × 5
adcode name center level geometry
<chr> <chr> <chr> <chr> <MULTIPOLYGON [°]>
1 442100 东沙群岛 116.887312,20.617512 city (((115.9433 21.09745, 115.95 21.11…
Simple feature collection with 1 feature and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 108.9287 ymin: 19.17894 xmax: 109.7694 ymax: 19.92575
Geodetic CRS: WGS 84
# A tibble: 1 × 5
adcode name center level geometry
<chr> <chr> <chr> <chr> <MULTIPOLYGON [°]>
1 460400 儋州市 109.576782,19.517486 city (((109.4322 19.91302, 109.4253 19.91…
Simple feature collection with 1 feature and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 97.8483 ymin: 39.65426 xmax: 98.52018 ymax: 39.99979
Geodetic CRS: WGS 84
# A tibble: 1 × 5
adcode name center level geometry
<chr> <chr> <chr> <chr> <MULTIPOLYGON [°]>
1 620200 嘉峪关市 98.277304,39.786529 city (((97.85974 39.7169, 97.85827 39.71…
X = list.files("./GeoMapData_CN/citys", recursive = T, full.names = T)
X2=X[-which(X %in% c("./GeoMapData_CN/citys/620200.json"
,"./GeoMapData_CN/citys/460400.json"
,"./GeoMapData_CN/citys/442100.json"
,"./GeoMapData_CN/citys/442000.json"
,"./GeoMapData_CN/citys/441900.json"
))]
map_list <- lapply(
X = X2,
FUN = sf::read_sf
)